<template>
	<view>
		<u-cell-group>
			<u-cell :value="item.deal_text" :title="item.nickname" v-for="item in highsealist" :key="item.id">
				<view slot="label">
					<text style="color: rgb(144, 145, 147)">客户来源：{{item.source.name}}</text>
					<view>
						<u-button type="primary" text="详情" :customStyle="btnStyle" size="mini"
							@click="toPages(item, 'info')"></u-button>
						<u-button type="success" text="分配" :customStyle="btnStyle" size="mini"
							@click="toPages(item, 'allot')"></u-button>
						<u-button type="warning" text="申请" :customStyle="btnStyle" size="mini"
							@click="changeConfirm(item, 'apply')"></u-button>
						<u-button type="error" text="删除" :customStyle="btnStyle" size="mini"
							@click="changeConfirm(item, 'del')"></u-button>
					</view>
				</view>
			</u-cell>
		</u-cell-group>
		<!-- 消息提示 -->
		<u-toast ref="uToast"></u-toast>
		<!-- 确认框 -->
		<u-modal :show="applyShow" :content='applyContent' :showCancelButton="true" @cancel="applyShow = false"
			@confirm="applyConfirm"></u-modal>
		<u-modal :show="delShow" :content='delContent' :showCancelButton="true" @cancel="delShow = false"
			@confirm="delConfirm"></u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				btnStyle: {
					width: '10%',
					display: "inline-block",
					marginRight: '5px',
					marginTop: '10px',
					lineHeight: '20px'
				},
				highsealist: [],
				LoginUser: {},
				applyShow: false,
				delShow: false,
				applyContent: '确认是否申请当前客户？',
				delContent: '确认是否删除当前客户？',
				busid: 0
			}
		},
		onShow() {
			this.$u.auth.check()
			this.LoginUser = uni.getStorageSync('LoginUser') ? uni.getStorageSync('LoginUser') : {};
			this.getHighseaData()
		},
		methods: {
			async getHighseaData() {
				let result = await this.$u.api.business.HighseaIndex()
				if (result.code == 1) {
					this.highsealist = result.data
				}
			},
			toPages(item, msg) {
				if (msg == 'info') {
					uni.navigateTo({
						url: `/pages/business/highsea/info?busid=` + item.id
					})
				} else {
					uni.navigateTo({
						url: `/pages/business/highsea/allot?busid=${item.id}&nickname=${item.nickname}`
					})
				}
			},
			async applyConfirm() {
				this.applyShow = false
				let result = await this.$u.api.business.HighseaOperate({
					busid: this.busid,
					adminid: this.LoginUser.id,
					status: 'apply'
				})
				if (result.code == 1) {
					this.$refs.uToast.show({
						type: 'success',
						message: result.msg,
					})
					this.getHighseaData()
				} else {
					this.$refs.uToast.show({
						type: 'error',
						message: result.msg,
					})
				}
			},
			async delConfirm() {
				this.delShow = false;
				let result = await this.$u.api.business.HighseaDel({
					busid: this.busid,
					adminid: this.LoginUser.id
				})
				if (result.code == 1) {
					this.$refs.uToast.show({
						type: 'success',
						message: result.msg,
					})
					this.getHighseaData()
				} else {
					this.$refs.uToast.show({
						type: 'error',
						message: result.msg,
					})
				}
			},
			changeConfirm(item, msg) {
				this.busid = item.id
				if (msg == 'apply') {
					this.applyShow = true
					this.applyContent = `确认是否申请${item.nickname}客户？`
				} else {
					this.delShow = true
					this.delContent = `确认是否删除${item.nickname}客户？`
				}
			}
		}
	}
</script>

<style>
</style>